<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fns" uri="/WEB-INF/tlds/fns.tld"%>
<!DOCTYPE html>
<html>
	<head>
		<title>按钮添加</title>
		<!-- 引入公用Js与Css -->
  		<%@include file="/view/common/resource.jsp" %>
	</head>
	<body>
		<div id="wrap">
			
			<div class="clearfix mt10 mr10 ml10">
				<form id="menuBtnForm" class="form-horizontal" action="<%=basePath%>/sys/menuBtn/addSave" method="post">
					<input type="hidden" name="menuId" value="${menuBtn.menuId }"/>
					<dl class="ml10">
						<dd class="clearfix pt10">
							<label class="w80 mr10 pull-left text-right line-height30">按钮名称:</label>
							<div class="w200 input-group input-group-sm" >
					            <input type="text" class="form-control" id="btnName" name="btnName" placeholder="请填写按钮的名称(必填项)">
							</div>
						</dd>
						
						<dd class="clearfix pt10">
							<label class="w80 mr10 pull-left text-right line-height30">按钮权限:</label>
							<div class="w200 input-group input-group-sm" >
					            <input type="text" class="form-control" id="btnPermissions" name="btnPermissions" placeholder="请填写按钮的权限(必填项)">
							</div>
						</dd>
					
						<dd class="clearfix pt30 ml110">
							<p class="radius3 bg_blue text-center w200 line-height30 mt10">
								<a href="javascript:" onclick="addSave();" class="color_white show">确认添加</a>
							</p>
						</dd>
					</dl>
				</form>
			</div>
		</div>
		<script type="text/javascript">
	    var validate = null;
	    $(document).ready(function(){
	    	validate = $('#menuBtnForm').validate({
	    		onkeyup:false,
				onfocusout: function(element){
					if (element.value != null && element.value != "") {
						$(element).valid();
					}
			    },
				rules:{
					"btnName":{
						required:true
					},
					"btnPermissions":{
						required:true
					}
				},
				messages:{
					"btnName":{
						required:"按钮名称必填"
					},
					"btnPermissions":{
						required:"按钮权限必填"
					}
				},
				errorPlacement: function(error, element) {
					layer.tips(error.text(), '#'+element.attr("name"), {
					  tips: [2, '#78BA32']
					});
				}
			});
	    });
	    
    	/* 数据保存 */
	    function addSave() {
    		
    		// 验证数据
	    	if (!validate.form()) {
	    		return false;
	    	}
	    	
    	    var actionurl=$('#menuBtnForm').attr('action');//提交路径
    	    
    	    $("#menuBtnForm").ajaxSubmit({
    	    	type:"post",
    	    	url:actionurl,
    	    	dataType: "json",
    	    	success:function(data){
        	    	if (data.success) {
    	   	        	// 成功后跳转首页
    	   	            layer.msg("按钮添加成功", {icon: 6, time:1000}, function() {
    	   	            	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    	   	            	parent.layer.close(index);
    	   	            });
    	   	        } else {
    	   	      		// 失败提醒
    	   	        	layer.msg(data.msg, {icon: 5});
    	   	        }
       	    	}
    	    }); 
	    }
    </script>
	</body>
</html>
